package com.itluma.isWOak.controller;

import com.itluma.isWOak.pojo.AdminInfo;

import com.itluma.isWOak.pojo.FunctionInfo;
import com.itluma.isWOak.service.AdminRoleService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author MS
 * @date 2021/4/1 19:05
 **/

@Controller
public class IndexController{

    @Autowired
    private AdminRoleService adminRoleService;

    @RequestMapping("/index")
    public ModelAndView show(HttpSession session){
        //对象里就是登陆的user
        Subject subject = SecurityUtils.getSubject ();
        AdminInfo admin = (AdminInfo) subject.getPrincipal ();
        //拿到所有权限
        List<FunctionInfo> listAll = adminRoleService.findbyAdmin (admin);

        //获取页面展示信息
        List<FunctionInfo> list = new ArrayList<> ();
        listAll.forEach ((e) -> {
            if (e.getLevel () == 1) {
                list.add (e);
            }
        });
        ModelAndView mv = new ModelAndView ();
        session.setAttribute ("list", list);
        mv.setViewName ("index");

        return mv;
    }

}